package panel.shopDetail
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.TimeToStr;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import panel.stars.StarGroup;
	
	import struct.Restaurant;
	import struct.UserComment;
	
	public class CommentBox extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var _width:Number = 0;
		private var _height:Number = 0;

//		private var back:Sprite;
		private var userNameText:TextField;
		private var timeText:TextField;
		private var infoText:TextField;
		private var star:StarGroup;
		
		private var thisHeight:Number;
		
		private var smallBack:Bitmap;;
		
		public function CommentBox(stage:Stage,loader:ResourceLoader,lang:Lang,uri:URI,wid:Number,hei:Number)
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			_width = wid;
			_height = hei;
			
			initThis();
		}
		
		private function initThis():void
		{	
			smallBack = new _loader.uiManager.componentBack as Bitmap;
			this.addChild(smallBack);
			smallBack.width = _width;
			smallBack.height = _height;
			
			userNameText = new TextField;
			userNameText.wordWrap = false;
			userNameText.multiline = false;
			userNameText.mouseEnabled =false;
			userNameText.autoSize = TextFieldAutoSize.LEFT;
			this.addChild(userNameText);
			
			timeText = new TextField;
			timeText.wordWrap = false;
			timeText.multiline = false;
			timeText.mouseEnabled =false;
			timeText.autoSize = TextFieldAutoSize.RIGHT;
			this.addChild(timeText);
			
			infoText = new TextField;
			infoText.wordWrap = true;
			infoText.multiline = true;
			infoText.mouseEnabled =false;
			infoText.autoSize = TextFieldAutoSize.LEFT;
			infoText.width = _width * .9;
			this.addChild(infoText);
			
			star = new StarGroup(StarGroup.READ_STARS);
			star.scaleX = .6;
			star.scaleY = .6;
			this.addChild(star);
		}
		
		public function changeData(obj:UserComment):void
		{
			TextFieldUtils.setHtmlText(userNameText,HtmlText.formatSizeColor(obj.userName + ":",0x000000));
			userNameText.width = userNameText.textWidth + 5;
			userNameText.width = userNameText.textHeight + 5;
			userNameText.x = _width * .05;
			userNameText.y = _height * .05;
			
			TextFieldUtils.setHtmlText(timeText,HtmlText.formatSizeColor(TimeToStr.formatYearAndDay(obj.userCommentTime),0x000000));
			timeText.width = timeText.textWidth + 5;
			timeText.width = timeText.textHeight + 5;
			timeText.x = _width - _width * .05 - timeText.width;
			timeText.y = _height * .05;
			
			star.starLevel = obj.commentStarLevel;
			star.x = userNameText.x;
			star.y = userNameText.y + userNameText.height + _height * .05;
			
			TextFieldUtils.setHtmlText(infoText,HtmlText.formatSizeColor(obj.commentContent,0x000000));
			infoText.width = infoText.textWidth + 5;
			infoText.x = userNameText.x;
			infoText.y = userNameText.y + userNameText.height + _height * .1 + star.height;
			
			thisHeight = infoText.y + infoText.height + _height * .1;
			
			smallBack.height = this.height;
		}
		
		public override function get height():Number
		{
			return thisHeight;
		}
	}
}